package com.szrt.java.day20161227.demo03;

import java.util.Arrays;

import org.junit.Test;

public class ArrayAddTest {

	@Test
	public void add(){
		
		int[] oldArray = new int[]{5,4,3,2,1};
		
		int num = 9;
		
		int oldLen = oldArray.length;
		
		//1 造1个数组 类型相同 数组的长度是原来的长度+1
		
		int[] newArray = new int[oldLen+1];
		
		//2 把原来的数组中的值依次复制过来 循环
		for(int index =0;index<oldLen;index++){
			
			//拿到旧数组的值
			int value = oldArray[index];
			newArray[index] = value;
		}
		System.out.println(Arrays.toString(newArray));
		newArray[oldLen] = num;
		System.out.println(Arrays.toString(newArray));
	}
	
}
